package message;



public class Message {
	private MessageType type;
	private String clientId;
	private String orderId;
	@SuppressWarnings("unused")
	private String symbol;
	@SuppressWarnings("unused")
	private int operation;
	@SuppressWarnings("unused")
	private double price;
	private double lastPrice;
	private int qty;
	private int leavesQty;
	private int lastQty;
	private int cumQty;
	private String text;

	public Message(Order order) {
		this.clientId = order.getClientId();
		this.orderId = order.getOrderId();
		this.price = order.getPrice();
		this.qty=order.getQty();
		this.cumQty=order.getCumQty();
		this.leavesQty=order.getLeavesQty();
		
		
	}

	


	public void setText(String text) {
		this.text = text;
	}




	public String getClientId() {
		return clientId;
	}




	public void setLastPrice(double lastPrice) {
		this.lastPrice = lastPrice;
	}

	public void setLastQty(int lastQty) {
		this.lastQty = lastQty;
	}

	@Override
	public String toString() {
		StringBuilder row = new StringBuilder("35=8");
		row.append("|11=" + orderId);
		if (type == MessageType.ACK) {
			row.append("|39=0");
			return row.toString();
		}
		row.append("|38=" + qty);
		row.append("|14=" + cumQty);
		row.append("|151=" + leavesQty);
		row.append("|31=" + lastPrice);
		row.append("|32=" + lastQty);
		if (type == MessageType.PARTFILL) {
			row.append("|39=1");
		}
		if (type == MessageType.FILL) {
			row.append("|39=2");
		}
		if (type == MessageType.CANCEL) {
			row.append("|39=4");			
		}
		if (type == MessageType.REJECT) {
			row.append("|39=8");
		}
		if (!"".equals(text)) row.append("|58=" + text);
			
		return row.toString();
	}

	public void setType(MessageType type) {
		this.type = type;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	public void setOperation(int operation) {
		this.operation = operation;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public void setQty(int qty) {
		this.qty = qty;
	}

	public void setLeavesQty(int leavesQty) {
		this.leavesQty = leavesQty;
	}

	public void setCumQty(int cumQty) {
		this.cumQty = cumQty;
	}

}
